package sort;
//冒泡排序
public class Bubble {
    public static void sort(Comparable[] a){
        for(int i = a.length-1 ; i > 0; i--){
            for (int j = 0; j<i; j++){
                if (grate(a[j],a[j+1])){
                    exch(a,j,j+1);
                }
            }
        }
    }
    //判断两个数值的大小
    private static Boolean grate(Comparable x, Comparable y){
    return x.compareTo(y) >0;
    }
    //交换两个元素的位置
    private static void exch(Comparable[] a, int i ,int j){
        Comparable tem = a[i];
        a[i] = a[j];
        a[j] = tem;
    }
}
